package chain;

import org.reflections.Reflections;
import org.reflections.scanners.SubTypesScanner;

import java.util.ServiceLoader;
import java.util.Set;

/**
 * 责任链控制器
 * 处理所有任务
 */
public class ControlHandler {

    /**
     * 处理整个任务链条
     */
    void process(ChainRequest chainRequest) {
        //查找下一个处理器，并掉用他

    }
    void init() throws ClassNotFoundException {
        WorkflowSayHandler workflowSayHandler = new WorkflowSayHandler();
        Class<?> clazz = this.getClass().getClassLoader().loadClass("chain.Handler");
        Reflections reflections = new Reflections("chain",new SubTypesScanner(true));
        Set<Class<? extends WorkflowHandler>> subClazz = reflections.getSubTypesOf(WorkflowHandler.class);

    }

    public static void main(String[] args) {
        ServiceLoader<WorkflowHandler> s = ServiceLoader.load(WorkflowHandler.class);
        for (Handler handler : s) {
            System.out.println(handler.getClass().getName());
        }
        ControlHandler c = new ControlHandler();
        try {
            c.init();
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
